<select id="province" name="pid" class="input input-auto" >
	<option value="">请选择</option>
</select>
<select id="city" name="cid" class="input input-auto hidden" >
	<option value="">请选择</option>
</select>
<select id="area" name="aid" class="input input-auto hidden" >
	<option value="">请选择</option>
</select>
<script id="province_list_tpl" type="text/html">
	<option value="">请选择</option>
	{{# for(var i = 0, len = d.data.length; i < len; i++){ }}
		<option {{# if(d.data[i].id==pid){ }}selected{{# } }} value="{{ d.data[i].id }}">{{ d.data[i].name }}</option>
	{{# } }}
</script>
<script id="city_list_tpl" type="text/html">
	<option value="">请选择</option>
	{{# for(var i = 0, len = d.data.length; i < len; i++){ }}
		<option {{# if(d.data[i].id==cid){ }}selected{{# } }} value="{{ d.data[i].id }}">{{ d.data[i].name }}</option>
	{{# } }}
</script>
<script id="area_list_tpl" type="text/html">
	<option value="">请选择</option>
	{{# for(var i = 0, len = d.data.length; i < len; i++){ }}
		<option {{# if(d.data[i].id==aid){ }}selected{{# } }} value="{{ d.data[i].id }}">{{ d.data[i].name }}</option>
	{{# } }}
</script>
<script>
	var func = false;
	$('select').click(function(){
		func = true;
	});
    if(selectc == true) {
        $('[name=cid]').removeClass('hidden');
    }
    if(selecta == true){
        $('[name=aid]').removeClass('hidden');
    }
	$.getJSON('__ROOT__/admin/city/ajax_get?type=province', {}, function(res){
		var tpl = $("#province_list_tpl").html();
		laytpl(tpl).render(res, function(render){
			$("#province").html(render);
		});
		if(pid != ''){
            $('[name=pid]').change();
		}
	});
	$('[name=pid]').change(function(){
		pid = $(this).val();
		if(selectc == true){
			$.getJSON('__ROOT__/admin/city/ajax_get?type=city&id='+pid, {}, function(res){
				var tpl = $("#city_list_tpl").html();
				laytpl(tpl).render(res, function(render){
					$("#city").html(render);
				});
				if(selectc == true){
					if(cid != ''){
                        $('[name=cid]').change();
					}
				}
			});
		}
		if(func == true){
			select_p();
		}
	});
	$('[name=cid]').change(function(){
		cid = $(this).val();
		if(selecta == true && cid){
			$.getJSON('__ROOT__/admin/city/ajax_get?type=area&id='+cid, {}, function(res){
				var tpl = $("#area_list_tpl").html();
				laytpl(tpl).render(res, function(render){
					$("#area").html(render);
				});
			});
		}
		if(func == true){
			select_c();
		}
	});
	$('[name=aid]').change(function(){
		aid = $(this).val();
		$('[name=aid]').removeClass('hidden');
		if(func == true){
			select_a();
		}
	});
</script>